<?php
/**
 * Created by b17
 * 3/22/12 8:23 PM
 */

namespace Managers\Builder;

class UserPaymentBuilder extends GenericBuilder
{
    const TABLE = '\Catalog\UserPayment';

    protected function _getQueryBuilder()
    {
        return parent::_getQueryBuilder()
            ->select('up, u')
            ->from(self::TABLE, 'up')
            ->join('up.user', 'u');
    }

    public function setCreatedDateRange(\DateTime $start, \DateTime $end)
    {
        $this->_qb->andWhere('up.createsAt >= :start')->setParameter('start', $start)
            ->andWhere('up.createsAt <= :end')->setParameter('end', $end);
        return $this;
    }

    public function getTotal()
    {
        parent::getTotal('up');
    }

    public function setDateStart($start)
    {
        if (is_string($start)) {
            $start = $this->_createDateTime($start);
        }
        if ($start instanceof \DateTime) {
            $this->_qb->andWhere('up.createsAt > :start')->setParameter('start', $start);
        }
        return $this;
    }

    public function setDateEnd($end)
    {
        if (is_string($end)) {
            $end = $this->_createDateTime($end);
        }
        if ($end instanceof \DateTime) {
            $this->_qb->andWhere('up.createsAt < :end')->setParameter('end', $end);
        }
        return $this;
    }
}
